<script type="text/javascript">
$(function() {
    $("input:checkbox[value^=admin]").click(function(){
        n = $(this).attr('name');
        if ($(this).is(':checked')) 
        {
            $("input:checkbox[name=" + n + "]").attr('checked', true);
        }
        else //uncheck children
        {
            $("input[type=checkbox]").filter("[name=" + n + "]").attr('checked', false);                        
        }
    });   
});

</script>
<h1> User Module: Assign Perm to Role </h1>
<div class="success-message"><?=$this->successMessage; ?></div>
<div class="error-message"><?=$this->errorMessage; ?></div>

<form accept-charset="UTF-8" action="/en/user/role/assign-perm"
      method="POST">
<table>
<tr>
<td width="70%"> <b>Permissions</b> </td>
<td> <b><?=$this->rname; ?></b> (#<?=$this->rid; ?>)
</tr>
<?foreach ($this->allPermissions->moduleAllPermissions as $resource=>$p):?>
	<?foreach ($p  as $perm) :?>
    	<?if ($perm == 'administer %s') :?>
        <tr style="background-color:#EEEEEE;width:100%">
        <td> <b><?=$resource; ?></b> </td>
        <?else:?>
        <tr>
        <td> &nbsp; &nbsp; <?=sprintf($perm,$resource); ?> </td>
        <?endif?>       
        <td>
        <?if (in_array(sprintf($perm,$resource), $this->perm)) :?>  
            <input type="checkbox" checked value="<?=sprintf($perm,$resource); ?>" id="<?=str_replace(' ', '-',$perm) . '-' . $resource; ?>" name="role_<?=$resource; ?>[]"/>
        <?else: ?>
            <input type="checkbox"         value="<?=sprintf($perm,$resource); ?>" id="<?=str_replace(' ', '-',$perm) . '-' . $resource; ?>" name="role_<?=$resource; ?>[]"/>
        <?endif ?>
        </td>
        </tr>
   <?endforeach ?>
<?endforeach ?>
</table>
<input type="submit" class="form-submit" value="Save permissions" id="edit-submit" name="op"/>
<input type="hidden" id="rid" name="rid" value="<?=$this->rid?>"/>
<input type="hidden" id="rname" name="rname" value="<?=$this->rname?>"/>
</form>      